package com.ruanjian2001.controller;

import com.ruanjian2001.Service.UserService;
import com.ruanjian2001.entity.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 修改用户信息
 */
public class ModifyServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");

        User uss = (User) request.getSession().getAttribute("user");

        User user = new User();
        user.setUsername(uss.getUsername());
        user.setPassword(request.getParameter("password"));
        user.setGender(request.getParameter("radiobutton"));
        user.setTelephone(request.getParameter("text2"));

        UserService us = new UserService();
        boolean bool = us.Mondify(user);

        if(bool){
            request.getSession().removeAttribute("user");
            response.sendRedirect(request.getContextPath() + "/client/Modify.jsp");
        }else{
            System.out.println("修改失败");
        }

        System.out.println(user);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doPost(request,response);
    }
}
